<template>
  <div class="login-page">
    <div class="login-page-window">
      <h2>欢迎使用视频会议</h2>
      <el-form
        class="login-page-form"
        :model="formData"
        :rules="formRules"
        ref="formRef"
      >
        <el-form-item label="房间号:" prop="roomId">
          <el-input
            v-model="formData.roomId"
            placeholder="请输入访问的房间号"
            maxlength="20"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="用户名:" prop="username">
          <el-input
            v-model="formData.username"
            placeholder="请输入用户名"
            maxlength="20"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="性 别:" prop="sex">
          <el-radio-group v-model="formData.sex">
            <el-radio label="boy">男</el-radio>
            <el-radio label="girl">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-button type="primary" class="login-page-enter-btn" @click="enter">
          进入
        </el-button>
      </el-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();

const formRef = ref();
const formData = reactive({
  roomId: "",
  username: "",
  sex: "boy",
});

const formRules = reactive({
  roomId: [{ required: true, message: "请输入房间号", trigger: "blur" }],
  username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
  sex: [{ required: true, message: "请选择性别", trigger: "change" }],
});

const enter = () => {
  formRef.value.validate((valid: boolean) => {
    if (!valid) return;
    localStorage.setItem("userData", JSON.stringify(formData));
    router.push("/show");
  });
};
</script>

<style lang="scss" scoped>
.login-page {
  background: url("https://whcode-1304835985.cos.ap-nanjing.myqcloud.com/img/infinity-2764502.jpg")
    no-repeat;
  background-size: cover;
  width: 100%;
  height: 100vh;
  &-window {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 400px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 5px 5px 5px#999;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    h2 {
      margin-top: 30px;
    }
  }
  &-form {
    padding: 30px 100px;
  }
  &-enter-btn {
    width: 100%;
  }
}
</style>
